package com.dify.tool;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

/**
 * @author shl
 * @date 2024-06-27
 */
@SpringBootApplication
@EnableScheduling
@Slf4j
public class DifyApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableEnvironment env = new SpringApplication(DifyApplication.class).run(args).getEnvironment();
        String envPort = env.getProperty("server.port");
        String port = Objects.isNull(envPort) ? "9089" : envPort;
        String envContext = env.getProperty("server.servlet.context-path");
        String context = Objects.isNull(envContext) ? "" : envContext;
        String path = port + context + "/doc.html";
        String externalAPI = InetAddress.getLocalHost().getHostAddress();
        log.info("Access URLs:\n\t-------------------------------------------------------------------------\n\tswagger-path: \thttp://{}:{}\n\t-------------------------------------------------------------------------", externalAPI, path);
    }
}
